<template>
  <view class="container">
	   <view class="fixeds_top">
		<view class="top_address">
			<text class="backs" @click="backs()"></text>
			 我的商品
			<text class="tianjia" @click="tianjia()">添加商品</text>
		  </view>
		</view>
		<view class="top_tabars">
			<view v-bind:class="{ 'items_active': change==0, 'items': change!=0 }" @click="changes('0')">
				<text v-bind:class="{ 'line': change==0}">全部</text>
			</view>
			<view v-bind:class="{ 'items_active': change==1, 'items': change!=1 }" @click="changes('1')">
				<text v-bind:class="{ 'line': change==1}">审核中</text>
			 </view>
			<view v-bind:class="{ 'items_active': change==2, 'items': change!=2 }" @click="changes('2')">
				<text v-bind:class="{ 'line': change==2}">审核成功</text>
			</view>
			<view v-bind:class="{ 'items_active': change==3, 'items': change!=3 }" @click="changes('3')">
				<text v-bind:class="{ 'line': change==3}">审核失败</text>
			 </view>
		</view>
		
		<view class="lists">
			<scroll-view scroll-y="true" style="height: 100%;width: 100%;" @scroll="loadMores"  :refresher-threshold="100">
			  <view class="items" v-for="value in list">
				  <view class="centers" @click="infos(value)">
					  <view class="goods_images">
						  <image :src="value.good.images[0]" mode="" ></image>
					  </view>
					  <view class="goods_info">
						   <view class="title">{{value.good.name}}</view>
						   <view class="content">{{value.good.type_name}}</view>
						   <view class="price">出厂价：{{value.quoted_price}}</view>
						   <view class="num">起订量：{{value.num}}</view>
					  </view>
					  <view class="goods_status" v-if="value.status==1">审核中</view>
					  <view class="goods_status" v-if="value.status==2">审核成功</view>
					  <view class="goods_status" v-if="value.status==3">审核失败</view>
				  </view>
				  <view class="goods_btn">
					  <view class="btn-oks" v-if="value.status==1" @click="tabsss(value)">未通过</view>
					  <view class="btn-ok" v-if="value.status==1" @click="tongguo(value)">通过</view>
					  <view class="btn-oks" v-if="value.status==2" @click="tabs(value)">上架</view>
					  <view class="btn-oks" v-if="value.status==2" @click="tabss(value)">下架</view>
				  </view>
			  </view>
			</scroll-view>
		</view>
		
		<view class="black_moban" v-show="shows"></view>
		<view class="wuliu_top" v-show="shows">
			<view class="title">确定上架该商品</view>
			<view class="center">
				<view class="left" @click="close()">取消</view>
				<view class="right" @click="submits()">确认</view>
			</view>
		</view>
		
		
		<view class="black_moban" v-show="showss"></view>
		<view class="wuliu_top" v-show="showss">
			<view class="title">确定下架该商品</view>
			<view class="center">
				<view class="left" @click="closes()">取消</view>
				<view class="right" @click="submitss()">确认</view>
			</view>
		</view>
		
		
		<view class="black_moban" v-show="showsss"></view>
		<view class="wuliu_top" v-show="showsss">
			 <view class="titles">
				<textarea v-model="reason" placeholder="请输入未通过原因" class="index-title"></textarea>
			 </view>
			<view class="center">
				<view class="left" @click="closess()">取消</view>
				<view class="right" @click="submitsss()">确认</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		ajax
	} from '../../ajax.js';
	export default {
		data() {
		return {
			firstNum:1,
			num:20,
			type:0,
			list:[],
			change:0,
			shows:false,
			showss:false,
			showsss:false,
			value:'',
			values:'',
			valuess:'',
			reason:''
		  }
		},
		onLoad() {
			this.getlist()
			
		},
		onPullDownRefresh() {
			this.loadMores()
		},
		onReachBottom(e) {
			this.loadMores();
		},
		methods:{
			infos(value){
				uni.navigateTo({
					url:'/pages/mine/mygoods_info?id='+value.spec_id
				})
			},
			tongguo(value){
				let that =this
				
				ajax({
					url: 'goods/editGoodStatus',
					data: {
						token:uni.getStorageSync('token'),
						good_id: value.good_id,
						spec_id:value.spec_id,
						status:2,
						reason:''
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						if(res.data.code==1){
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
							this.showsss=false
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
				},
				error: function() {
						
				}
				});
			},
			tianjia(){
				uni.navigateTo({
					url:'/pages/mine/goodsadd'
				})
			},
			backs(){
				uni.navigateBack({
					
				})
			},
			loadMores(){
				let that = this
				let status = that.type
				let num = that.num
				let token = uni.getStorageSync('token')
				that.firstNum=that.firstNum+1
				if(that.firstNum>that.last_page){
					uni.showToast({
						title: "没有更多数据",
						icon:'none'
					})
					return
				}
				//that.list=[]
				ajax({
					url: 'address',
					data: {
						token: token,
						firstNum: that.firstNum,
						num: num,
						status: status
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data.data)
						//res.data.data.data[0].status_text='已发货'
						
						   res.data.data.data.slice(0).forEach(e => {
							  that.list.push(e);
							});
						
						that.last_page=res.data.data.last_page
						
					},
					error: function() {
							
					}
				});
			},
			submitsss(){
				let that =this
				let valuess=that.valuess
				if(that.reason==''){
					uni.showToast({
						title:'请输入未通过原因',
						duration: 1500,
						icon: 'none'
					});
				  return
				}
				ajax({
					url: 'goods/editGoodStatus',
					data: {
						token:uni.getStorageSync('token'),
						good_id: valuess.good_id,
						spec_id:valuess.spec_id,
						status:3,
						reason:that.reason
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						if(res.data.code==1){
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
							this.showsss=false
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
				},
				error: function() {
						
				}
				});
			},
			closess(){
				this.showsss=false
			},
			close(){
				this.shows=false
			},
			closes(){
				this.showss=false
			},
			submits(){
				let that =this
				let value=that.value
				ajax({
					url: 'goods/editGoodsDownOrUp',
					data: {
						token:uni.getStorageSync('token'),
						good_id: value.good_id
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						if(res.data.code==1){
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
							this.shows=false
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
				},
				error: function() {
						
				}
				});
			},
			submitss(){
				let that =this
				let values=that.values
				ajax({
					url: 'goods/editGoodsDownOrUp',
					data: {
						token:uni.getStorageSync('token'),
						good_id: values.good_id
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						if(res.data.code==1){
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						   this.showss=false
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
				},
				error: function() {
						
				  }
			   });
			},
			tabss(value){
				let that =this
			    that.values=value
			    that.showss=true
			},
			tabs(value){
			   let that =this
			   that.value=value
			   that.shows=true
			},
			tabsss(value){
				let that =this
				that.valuess=value
				that.showsss=true
			},
			changes(value){
				let that=this
				that.change=value
				that.type=value
				that.getlist()
				
			},
			getlist(){
				let that = this
				let status = that.type
				let firstNum = that.firstNum
				let num = that.num
				let token = uni.getStorageSync('token')
				that.list=[]
				ajax({
					url: 'goods/getMyGoods',
					data: {
						token: token,
						firstNum: firstNum,
						num: num,
						status: status
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data.data)
						//res.data.data.data[0].status_text='已发货'
						that.list = res.data.data.data
						that.last_page=res.data.data.last_page
						
					},
					error: function() {
							
					}
				});
			}
		 }
	}
</script>

<style lang="scss">
	page{
		background: #F7F7F7;
	}
	.black_moban{
		width: 750rpx;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		position: absolute;
		top: 0;
	}
	.wuliu_top{
		width: 620rpx;
		height: 207rpx;
		background-color: #FFFFFF;
		position: absolute;
		top: 401rpx;
		left: 65rpx;
		border-radius: 20rpx;
		.index-title{
			width: 96%;
			padding: 2%;
			height: 160rpx;
			overflow: hidden;
		 }
		.center{
			width: 100%;
			overflow: hidden;
			margin: 0rpx auto;
			
			.left{
				width: 50%;
				line-height: 90rpx;
				height: 90rpx;
				text-align: center;
				color: #333;
				background: #F7F7F7;
				float: left;
				border-bottom-left-radius:20rpx
			}
			.right{
				width: 50%;
				line-height: 90rpx;
				height: 90rpx;
				text-align: center;
				color: #FFFFFF;
				background: #FF7427;
				float: left;
				border-bottom-right-radius:20rpx
			}
		}
		.title{
			font-size: 32rpx;
			padding: 48rpx 0rpx 48rpx 0rpx;
			text-align: center;
		}
	}
	.top_tabars{
		width: 100%;
		height: 68rpx;
		position: fixed;
		top: 68rpx;
		z-index: 100;
		left: 0rpx;
		background: #F7F7F7;
		color: #333333;
		overflow: hidden;
		background: #F7F7F7;
		.items{
			float: left;
			width: 25%;
			overflow: hidden;
			height: 72rpx;
			line-height: 72rpx;
			text-align: center;
			font-size: 28rpx;
			color: #333333;
		}
		.line{
			width: 128rpx;
			line-height: 46rpx;
			height: 46rpx;
			display: inline-block;
			border-bottom: 2rpx solid #FF7427;
		}
		.items_active{
			float: left;
			width: 25%;
			overflow: hidden;
			height: 72rpx;
			line-height: 72rpx;
			text-align: center;
			font-size: 28rpx;
			color: #FF7427;
			
		}
	}
	.fixeds_top{
		position: fixed;
		width: 100%;
		z-index: 100;
		height: 68rpx;
		top: 0rpx;
		left: 0rpx;
		background: #F7F7F7;
	}
	.container{
		margin: 0rpx auto;
		padding: 0rpx 0rpx;
		.top_address{
			width: 100%;
			height: 69rpx;
			line-height: 69rpx;
			font-size: 32rpx;
			color: #333333;
			font-weight:550;
			text-align: center;
			position: relative;
			.backs{
				position: absolute;
				width: 38rpx;
				height: 38rpx;
				left: 12rpx;
				top: 12rpx;
				background: url(../../static/clq-image/back.png) no-repeat center;
				background-size: 100%;
				display: inline-block;
			}
			.tianjia{
				position: absolute;
				width: 128rpx;
				font-size: 26rpx;
				color: #FF7427;
				text-align: center;
				line-height: 38rpx;
				height: 38rpx;
				right: 10rpx;
				top: 20rpx;
				display: inline-block;
			}
		}
		.lists{
			width: 100%;
			margin: 144rpx auto auto auto;
			padding: 0rpx 0rpx;
			.items{
				width: 90%;
				padding: 2.5%;
				overflow: hidden;
				font-size: 28rpx;
				background-color: #FFFFFF;
				border-radius: 12rpx;
				margin: 20rpx auto;
				.centers{
					width: 100%;
					overflow: hidden;
					margin: 0rpx auto;
					font-size: 28rpx;
					.goods_images{
						float: left;
						width: 28%;
						image{
							width: 148rpx;
							height: 148rpx;
						}
					}
					.goods_info{
						width: 40%;
						float: left;
						.title{
							font-size: 28rpx;
							
						}
						.content{
							color: #555555;
							font-size: 20rpx;
						}
						.price{
							color: #D50000;
							font-size: 28rpx;
						}
						.num{
							color: #333333;
							font-size: 26rpx;
						}
						
					}
					.goods_status{
						width: 22%;
						float: left;
						color: #FF7427;
						font-size: 28rpx;
						text-align: right;
					}
				}
				.goods_btn{
					width: 100%;
					overflow: hidden;
					border-top: 2rpx solid #f7f7f7;
					.btn-ok{
						width: 108rpx;
						float: right;
						height: 48rpx;
						line-height: 48rpx;
						margin-left: 14rpx;
						border-radius: 24rpx;
						color: #FFFFFF;
						background: #FF7427;
						text-align: center;
					}
					.btn-oks{
						width: 108rpx;
						height: 48rpx;
						float: right;
						line-height: 48rpx;
						margin-left: 14rpx;
						border-radius: 24rpx;
						color: #FFFFFF;
						background:#FF7427;
						text-align: center;
					}
				}
			}
		}
	}
	
</style>
